@import '../../styles/var.less';

.k-table {
  background: var(--kui-color-back);
  border-radius: @radius;
  width: 100%;
  margin: 10px 0;
  box-sizing: border-box;
  position: relative;
  color: var(--kui-color-font);

  &-thead-sticky {
    position: sticky;
    position: -webkit-sticky;
    top: 0;
    z-index: 3;
  }




  .k-table-cell-fixed-left {
    position: sticky;
    left: 0;
  }

  .k-table-cell-fixed-right {
    position: sticky;
    right: 0;
  }

  .k-spin {
    position: absolute;
    width: 100%;
    height: 100%;
    left: 0;
    top: 0;
    z-index: 100;
    border-radius: @radius;

    .k-spin-loading {
      border-radius: @radius;
      background-color: var(--kui-color-spin);
    }
  }

  .k-table-container {
    width: 100%;
    border-radius: @radius;
  }

  table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--kui-color-back);
    margin: 0;
    border-radius: @radius;


    thead {
      border-bottom: 1px solid var(--kui-color-table-border);
    }

    tr th:first-child {
      border-top-left-radius: @radius;
    }

    tr th:last-child {
      border-top-right-radius: @radius;
    }




    .k-table {
      margin: -10px -10px -11px -10px
    }



    tr>th,
    tr>td {
      font-size: 14px;
      padding: 10px 16px;
      box-sizing: border-box;
      word-break: break-all;
      word-wrap: break-word;
      border-bottom: 1px solid var(--kui-color-table-border);
    }

    tr>th {
      background: var(--kui-color-table-header);
      font-weight: 500;
      overflow-wrap: break-word;
      text-align: left;
      padding: 16px;

      &[colspan]:not([colspan="1"]) {
        text-align: center;
      }
    }

    .k-table-header-col {
      display: flex;
      max-width: 100%;

      .k-table-header-title {
        display: flex;
        align-items: center;
        line-height: 1;
      }
    }


    .k-table-cell-sorter {
      cursor: pointer;
      user-select: none;

      .k-table-header-col {
        display: flex;
        flex-direction: row;
        align-items: center;
        line-height: 1;


      }

      .k-table-header-title {
        flex: 1;
        display: flex;
        align-items: center;
        line-height: 1;
      }

      &:hover {
        background: var(--kui-color-table-header-hover);
      }

      .k-table-sorter {
        display: inline-block;
        margin-left: 8px;
        vertical-align: middle;

        .k-icon {
          display: flex;
          align-items: center;
          font-size: 10px;
          line-height: 1;
          color: #ccc;
          height: 7px;
        }

        .active {
          color: var(--kui-color-main);
        }
      }
    }

    .k-table-cell-ellipsis {
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;

      .k-table-header-title {
        display: inline-block;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
    }

    th.k-table-cell-selection {
      text-align: center;
      padding: 0;

      .k-table-header-col {
        justify-content: center;
      }

      .k-table-header-title {
        align-items: center;
      }
    }

    tbody>tr {

      .k-table-cell-fixed-left,
      .k-table-cell-fixed-right {
        background-color: var(--kui-color-back);
      }

      &:hover {
        background: var(--kui-color-table-hover);

        .k-table-cell-fixed-left,
        .k-table-cell-fixed-right {
          background-color: var(--kui-color-table-hover);
        }
      }
    }

    .k-table-expand-row {
      &:hover {
        background: var(--kui-color-table-hover);
      }
    }

    td table {
      tr:last-child {
        border-bottom: none;
      }

      tbody>tr:hover {
        background: var(--kui-color-table-hover);
      }
    }
  }

  .k-table-thead {
    border-top-left-radius: @radius;
    border-top-right-radius: @radius;

    tr th:first-child,
    tr th:last-child {
      border-radius: 0;
    }
  }

  &-thead {
    overflow: auto;
  }

  &-header {
    padding: 10px;
    border-top: 1px solid var(--kui-color-table-border);
  }

  &-footer {
    padding: 10px;
    border-bottom: 1px solid var(--kui-color-table-border);
    background-color: var(--kui-color-table-header);
    border-bottom-left-radius: @radius;
    border-bottom-right-radius: @radius;
  }

  th>a,
  td>a {
    color: #3a95ff;
  }

  .k-empty {
    padding: 30px 0;
    box-sizing: content-box;
  }

  &-fixed {
    table {
      table-layout: fixed;
    }
  }

  &-header {
    word-break: break-all;
  }

  .k-table-cell-fixed-left-last,
  .k-table-cell-fixed-right-first {
    &::after {
      content: "";
      position: absolute;
      height: calc(100% + 1px);
      width: 30px;
      top: 0;
      pointer-events: none;
    }
  }

  &-ping-middle {
    .k-table-cell-fixed-right-first::after {
      box-shadow: inset -6px 0 6px -4px var(--kui-color-shadow);
      left: -30px;
    }

    .k-table-cell-fixed-left-last::after {
      box-shadow: inset 6px 0 6px -4px var(--kui-color-shadow);
      right: -30px;
    }
  }

  &-ping-right {
    .k-table-cell-fixed-left-last::after {
      box-shadow: inset 6px 0 6px -4px var(--kui-color-shadow);
      right: -30px;
    }
  }

  &-ping-left {
    .k-table-cell-fixed-right-first::after {
      box-shadow: inset -6px 0 6px -4px var(--kui-color-shadow);
      left: -30px;
    }
  }

  &-sm {
    table tr {

      th {
        padding: 10px 8px;
      }

      td {
        padding: 5px 8px;
      }
    }
  }

  &-lg {
    table tr {

      th {
        padding: 20px 16px;
      }

      td {
        padding: 16px;
      }
    }
  }

  .k-table-header+.k-table-container {
    table tr th:first-child {
      border-radius: 0;
    }

    table tr th:last-child {
      border-radius: 0;
    }
  }

  &-bordered {
    border: 1px solid var(--kui-color-table-border);
    border-radius: @radius;

    .k-table-footer {
      border-top: 1px solid var(--kui-color-table-border);
      border-bottom: none;
      border-bottom-left-radius: @radius;
      border-bottom-right-radius: @radius;
    }

    thead {
      th {
        border-bottom: 1px solid var(--kui-color-table-border);
        border-right: 1px solid var(--kui-color-table-border);
      }
    }

    .k-table-header {
      border-bottom: 1px solid var(--kui-color-table-border);
      border-top: none;
      border-top-left-radius: @radius;
      border-top-right-radius: @radius;
    }

    th,
    td {
      border-right: 1px solid var(--kui-color-table-border);
    }

    tr {
      &:first-child td {
        border-top: none;
      }

      &:last-child {
        border-bottom: none;

        td {
          border-bottom: none;
        }
      }
    }

    tr td:first-child,
    tr th:first-child {
      border-left: none;
    }

    tr td:last-child,
    thead tr:first-child th:last-child {
      border-right: none;
    }

    tr th:first-child,
    table thead,
    tr th {
      border-top: none;
    }

    .k-table-fixed-right {
      border-left: 1px solid var(--kui-color-table-border);
    }

    & .k-table {
      margin: -11px -10px -11px -11px;
      border-right: none;
    }
  }

  &-cell-selection {
    text-align: center;
  }

  &-selection-col {
    width: 50px
  }

  &-expand-icon-col {
    width: 50px;
    min-width: 50px;
  }

  &-row-expand-icon-cell {
    text-align: center;

    .k-icon {
      cursor: pointer;

      &:hover {
        color: var(--kui-color-main);
      }
    }
  }
}